<!--
 * @Descripttion: 慢直播列表
 * @Author: wang pingqi
 * @Date: 2021-12-07 11:19:47
 * @LastEditors: 杨镜
 * @LastEditTime: 2023-01-04 14:16:50
-->
<template>
  <div class="app-container">
    <el-form ref="listFilterRef" :model="list.filter" inline class="list-filter">
      <el-form-item prop="name">
        <el-input
          v-model="list.filter.name"
          placeholder="请输入直播名称搜索"
          clearable
        >
          <i slot="prefix" class="el-input__icon el-icon-search" />
        </el-input>
      </el-form-item>
      <el-form-item  prop="scenicId">
        <el-select v-model="list.filter.scenicId" clearable placeholder="关联景区搜索" filterable >
          <el-option
            v-for="item in scenicList"
            :key="item.id"
            :disabled="!item.status"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-button @click="reset">重置</el-button>
    </el-form>

    <div class="table-operation">
      <span>
        <AuthButton @click="c" name="新增" />
      </span>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <form-item-tip
      class="mb10"
      value="该功能配置后只会在微信小程序端生效"
    />
    
    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column align="center" type="index" />
      <el-table-column label="直播名称" prop="name" />
      <el-table-column label="封面图">
        <template slot-scope="scope">
          <PicViewer :value="scope.row.cover" tableCell />
        </template>
      </el-table-column>
      <el-table-column label="列表图">
        <template slot-scope="scope">
          <PicViewer :value="scope.row.imgPath" tableCell />
        </template>
      </el-table-column>
      <el-table-column label="关联景区" prop="scenicName"></el-table-column>
      <el-table-column label="创建时间" prop="createTime"></el-table-column>
      <el-table-column label="直播状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch 
            v-bind="{
              value: status,
              key: new Date().getTime(),
              'active-value': 1,
              'inactive-value': 0,
              'active-text': options[status],
              'inactive-text': options[status],
              ...(hasBtn[options[status ^ 1]]
                ? {
                  elPopconfirmProps: {
                    title: `确认${options[status ^ 1]}吗？`
                  }
                }
                : {
                  disabled: true,
                  elPopoverProps: {
                    content: `<i class='el-icon-warning'/> 权限不足`
                  }
                }),
            }"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{ row }">
          <auth-button @click="r({ id: row.id })" name="查看" />
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="直播名称" prop="name" verify>
          <el-input
            v-model="form.data.name"
            clearable
            maxlength="20"
            show-word-limit
            placeholder="请输入直播名称"
          />
        </el-form-item>
        <el-form-item label="关联景区" prop="scenicId" verify>
         <el-select v-model="form.data.scenicId" filterable placeholder="请选择">
          <el-option
            v-for="item in scenicList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
            :disabled="!item.status"
            >
          </el-option>
        </el-select>
        </el-form-item>
        <el-form-item label="推流地址" prop="pushUrl" verify>
          <el-input
            v-model="form.data.pushUrl"
            clearable
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            maxlength="300"
            show-word-limit
            placeholder="请输入推流地址"
          />
        </el-form-item>
        <el-form-item label="封面图" prop="cover" verify>
          <Imgpond valueType="string" v-model="form.data.cover" aspectRatio="138/120" :count="1" :size="10"/>
        </el-form-item>
        <el-form-item label="列表图" prop="imgPath" verify>
          <Imgpond valueType="array" v-model="form.data.imgPath" aspectRatio="345/158" :count="1" :size="10"/>
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () => useAdmateAdapter({
    urlPrefix: 'one-travel-api/sceniclive'
  }),
  data () {
    return {
      scenicList : [],
      options: {
        0: '暂停',
        1: '直播中',
      }
    }
  },
  created(){
    this.getScenicList();
  },
  methods: {
    async getScenicList(){
      let {data} = await this.$POST('one-travel-api/scenic/queryForList');
      this.scenicList = data;
    }
  }
}
</script>

<style lang="scss" scoped>
</style>

